package hhm.activeMQ.idontknow;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;

import hhm.activeMQ.idontknow.mq.MqClient;
import hhm.activeMQ.idontknow.mq.MqServer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
	public static void main(String[] args) {
		ApplicationContext mqServerContext = new ClassPathXmlApplicationContext("spring/spring-mq-server.xml");
		MqServer mqServer = (MqServer) mqServerContext.getBean("mqServer");
		if (mqServer != null) {
			Thread mqServerThread = new Thread(mqServer);
			mqServerThread.run();
		}

		ApplicationContext receiverContext = new ClassPathXmlApplicationContext("spring/spring-mq-receiver.xml");
		ReceiverHandle receiverHandle = (ReceiverHandle) receiverContext.getBean("receiverHandle");
		if (receiverHandle != null) {
			Thread t = new Thread(receiverHandle);
			t.start();
		}

		MqClient mqClient = (MqClient) receiverContext.getBean("mqClient");

		try {
			ObjectMessage message = mqClient.getSession().createObjectMessage(new Info("huanghaoming", "男"));
			mqClient.send(message);

		} catch (JMSException e) {
			e.printStackTrace();
		}

	}

}
